#ifndef PAKFILE_H
#define PAKFILE_H

#include <vector>
using std::vector;

#include <string>
using std::string;

//!Represent a file inside a zpak file.
class dataFile
{
public:
	//!Name of the file.
	string m_filename;

	//!Size of the file.
	int m_size;

	//!Offset of the start of the file inside the zpak file.
	int m_offset;
};

class CPakFile
{
private:
	//!Name of the zpak file.
	string m_filename;

	//!Number of files packed in the file.
	int m_numberOfFile;

	//!Buffer to store the zpak file
	char* m_buffer;

	//!Size of the zpak file.
	int m_sizeZPakFile;
	
	//!Array of dataFile. It stores info about all the file packed in a zpak file.
	vector<dataFile> m_dataFileArray;


public:
	//!Constructor.
	CPakFile(void);

	//!Destructor
	~CPakFile(void);

	//!Load a .zpak file.
	/*!
	\param filename Name of the .zpak file to load.
	\return True if the file was loaded. False if the loading failed.
	*/
	bool loadFile(const string& filename);

	//!Close the file.
	/*!
	\return True if the file is closed. False if it failed.
	*/
	bool closeFile(void);

	//!Get a pointer to a file present in the zpak file.
	/*!
	\param filename Name of the file to find in the zpak file.
	\param buffer pointer to the file.
	\param size Size of the buffer.
	\return True if the file was found. False if the file can't be found.
	*/
	bool getFile(const string& filename, char** buffer, int* size)const;

private:

	//!Unzip a zpak file.
	/*This function is called in loadFile. Once the file is loaded, unzip is called to uncompress the file and copy it 
	into a buffer.
	\param file Handle of the loaded zpak file.
	\return True if the file was uncompress successfuly. False if the uncompression failed.*/
	bool unzip(FILE* file);

	//!Make the list of file which are inside the zpak file.
	/*This function is called in the loadFile function once the file was uncompressed. 
	\return True if all the file were found. Fales if the funcion failed.*/
	bool makeListOfFile();
};

#endif
